#	$Id: Makefile 1015 2010-04-07 05:26:50Z phrakt $

.include "../share/mk/own.mk"


# Set to 'yes' to install the BSD-style startup script
BSD_INIT=	no

# Set to 'yes' to install the SystemV-style startup script
SYSV_INIT=	no



CONFFILES=	canopy.conf

CLEANFILES=	rc.canopy init.d/${HTTPD_EXEC_NAME}



INIT_TARGETS=

.if ${BSD_INIT} == "yes"
INIT_TARGETS+=	install-bsd
.endif

.if ${SYSV_INIT} == "yes"
INIT_TARGETS+=	install-sysv
.endif


# Variables specific to BSD-style initialization
BSD_RCFILE?=		/etc/rc.local
BSD_RCCONF?=		/etc/rc.conf.local
BSD_STDFLAGS?=


# Variables specific to SystemV-style initialization

.if exists(/etc/init.d)
SYSV_INITDIR?=		/etc/init.d
.elif exists(/etc/rc.d/init.d)
SYSV_INITDIR?=		/etc/rc.d/init.d
.elif exists(/sbin/init.d)
SYSV_INITDIR?=		/sbin/init.d
.endif

SYSV_DFLTDIR?=		/etc/default
SYSV_INITBIN?=		${HTTPD_EXEC_NAME}
SYSV_RUNLEVEL?=		3



.SUFFIXES: .in

.in:
	@sed -e 's/\(@EXECPATH@\)/${HTTPD_EXEC_PATH:S/\//\\\//g}/g' \
	    -e 's/\(@PIDFILE@\)/${HTTPD_PIDFILE_PATH:S/\//\\\//g}/g' \
	    -e 's/\(@CTLSOCK@\)/${HTTPD_CTLSOCK_PATH:S/\//\\\//g}/g' \
	    -e 's/\(@NAME@\)/${HTTPD_NAME}/g' \
	    -e 's/\(@VERSION@\)/${HTTPD_VERSION}/g' \
	    ${.IMPSRC} > ${.TARGET}


all:


install: realinstall ${INIT_TARGETS}


realinstall: ${CONFFILES}
	@if ! [ -d ${DESTDIR}${ETCDIR} ]; then				\
		echo "Creating directory ${DESTDIR}${ETCDIR}";		\
		mkdir -p ${DESTDIR}${ETCDIR};				\
	fi
	@for c in ${CONFFILES}; do					\
		if [ ! -e ${DESTDIR}${ETCDIR}/$$c ]; then		\
			echo ${INSTALL} -c -o ${ETCOWN} -g ${ETCGRP}	\
			    -m ${ETCMODE} $$c ${DESTDIR}${ETCDIR};	\
			${INSTALL} -c -o ${ETCOWN} -g ${ETCGRP}		\
			    -m ${ETCMODE} $$c ${DESTDIR}${ETCDIR};	\
		fi							\
	done


#
# Installation steps specific to systems with BSD-style initialization
#
install-bsd: rc.canopy
	@echo ${INSTALL} -c -o ${ETCOWN} -g ${ETCGRP} -m ${ETCMODE} 	\
	    rc.canopy ${DESTDIR}${ETCDIR}
	@${INSTALL} -c -o ${ETCOWN} -g ${ETCGRP} -m ${ETCMODE}		\
	    rc.canopy ${DESTDIR}${ETCDIR}
	@if [ ! -e ${BSD_RCCONF} ]; then				\
		echo "Creating ${BSD_RCCONF}";				\
	fi
	@if ! grep canopy_flags ${BSD_RCCONF} >> /dev/null; then	\
		echo >> ${BSD_RCCONF};					\
		echo "canopy_flags=NO		# for normal use: "	\
		    "\"${BSD_STDFLAGS}\"" >> ${BSD_RCCONF};		\
	fi
	@if ! grep canopy ${BSD_RCFILE} >> /dev/null; then		\
		echo >> ${BSD_RCFILE};					\
		echo ". ${DESTDIR}${ETCDIR}/rc.canopy" >> ${BSD_RCFILE};\
	fi


#
# Installation steps specific to systems with SystemV-style initialization
#
install-sysv: init.d/${SYSV_INITBIN}
	@${INSTALL} -c -o ${ETCOWN} -g ${ETCGRP} -m ${BINMODE}		\
	    init.d/${SYSV_INITBIN} ${SYSV_INITDIR}
	@if ! which update-rc.d; then					\
		echo "Using update-rc.d";				\
		update-rc.d ${SYSV_INITBIN} defaults			\
	fi
	@echo "Creating ${SYSV_DFLTDIR}/${SYSV_INITBIN}"
	@echo "HTTPD_OPTS=''" >> ${SYSV_DFLTDIR}/${SYSV_INITBIN}


clean:
	rm -f ${CLEANFILES}
